package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.domain.AjaxResult;

import com.zzyl.nursing.domain.PageBean;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.dto.ReservationDto;
import com.zzyl.nursing.dto.TimeSlotCountDto;
import com.zzyl.nursing.service.MemberOrdersService;
import com.zzyl.serve.domain.NursingProject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.Date;
import java.util.List;

import static com.zzyl.common.core.domain.AjaxResult.error;
import static com.zzyl.common.core.domain.AjaxResult.success;

@RestController
@RequestMapping("/member")
@Api(tags = "家属端管理")
public class MemberOrdersController {
    @Autowired
    private MemberOrdersService memberOrdersService;
    @GetMapping("/orders/project/page")
    public AjaxResult findAllPage(String name,
                                  @RequestParam(defaultValue = "1") Integer pageNum,
                                  @RequestParam(defaultValue = "10") Integer pageSize,
                                  Integer status){
        PageBean<NursingProject> pb = memberOrdersService.findAllPage(name, pageNum, pageSize, status);
        return AjaxResult.success()
                .put("rows", pb.getRows())
                .put("total", pb.getTotal());
    }

    @GetMapping("/orders/project/{id}")
    public AjaxResult findById(@PathVariable Long id){
        NursingProject nursingProject = memberOrdersService.selectById(id);
        return success(nursingProject);
    }
    @GetMapping("/reservation/cancelled-count")
    public AjaxResult getCancelledCount() {
        int cancelledCount = memberOrdersService.getTodayCancelledCount();
        return AjaxResult.success(cancelledCount);
    }
    @GetMapping("/reservation/countByTime")
    @ApiOperation("查询每个时间段剩余预约次数")
    public AjaxResult getCountByTime() {
        List<TimeSlotCountDto> timeSlotCounts = memberOrdersService.getCountByTime();
        return AjaxResult.success(timeSlotCounts);
    }
    @PostMapping("/reservation")
    public AjaxResult insertReservation(@RequestBody ReservationDto dto){
        boolean result =memberOrdersService.insertReservation(dto);
        return result ? success() : error();
    }
    @GetMapping("/reservation/page")
    public AjaxResult findReservationPage(@RequestParam(defaultValue = "1")  Integer pageNum,
                                          @RequestParam(defaultValue = "10") Integer pageSize,
                                          Integer status){
        PageBean<Reservation> reservations = memberOrdersService.findReservationPage(pageNum ,pageSize, status);
        return AjaxResult.success(reservations);
    }


}
